<!DOCTYPE html>
<html>

<head>

    <meta charset="utf-8">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">


    <title> - 个人资料</title>
    <meta name="keywords" content="">
    <meta name="description" content="">

    <link rel="shortcut icon" href="favicon.ico">
    <link href="/static/hAdmin/css/bootstrap.min.css?v3.3.6" rel="stylesheet">
    <link href="/static/hAdmin/css/font-awesome.css?v=4.4.0" rel="stylesheet">
    <!-- Sweet Alert -->
    <link href="/static/hAdmin/css/plugins/sweetalert/sweetalert.css" rel="stylesheet">
    <link href="/static/hAdmin/css/animate.css" rel="stylesheet">
    <!--<link href="/static/hAdmin/css/style.css?v=4.1.0" rel="stylesheet">-->
    <link href="/static/hAdmin/css/style2.css?version 4.0" rel="stylesheet">
    <link href="/static/hAdmin/css/plugins/toastr/toastr.min.css" rel="stylesheet">
    <style>
        .addList {
            padding: 10px 30px 10px 30px;
            height: 90px;
            margin-top: 3px;
        }

    </style>
</head>

<body class="gray-bg">
    <div class="wrapper wrapper-content">
        <span id="gloUrl" style="display: none"></span>
        <div class="row animated fadeInRight">
            <div class="col-xs-4">
                <div class="col-sm-12">
                    <div class="ibox float-e-margins">
                        <div class="ibox-title">
                            <h5>账号资料</h5>
                        </div>
                        <div>

                            <div class="ibox-content profile-content">
                                <h4>昵称 ： <strong id="name"></strong></h4>
                                <p><i class="fa fa-map-marker"></i> 中国</p>


                                <div class="row m-t-lg">
                                    <div class="col-sm-10">

                                        <h5><strong>注册日期：</strong> <span id="totalNum">&nbsp;33</span> </h5>
                                    </div>
                                    <br>
                                    <div class="col-sm-10">
                                        <button class="btn btn-danger" id="logout">退出登录</button>
                                        <button class="btn btn-primary userFun" data-toggle="modal" data-target="#myModalDe" id="edit">编辑信息</button>
                                        <button class="btn btn-primary userFun" data-toggle="modal" data-target="#myModalRe" id="resetpwd">重置密码</button>
                                    </div>
                                </div>

                            </div>
                        </div>
                    </div>
                </div>
                <div class="col-sm-12 userFun">
                    <div class="ibox float-e-margins">
                        <div class="ibox-title">
                            <h5>账号绑定信息</h5>
                        </div>

                        <div class="ibox-content profile-content" style="text-align: center">
                            <div class="row m-t-lg">
                                <div class="col-sm-10" >
                                    <div class="col-xs-4 col-lg-push-4" >
                                        <img class="img-responsive img-circle" src="" alt="暂无" id="currimg">
                                    </div>
                                </div>
                            </div>
                            <div class="row m-t-lg">
                                <div class="col-sm-10">
                                    <h5><strong>姓名：</strong>
                                        <span id="curruserName"></span>
                                    </h5>
                                </div>
                            </div>
                            <div class="row m-t-lg">
                                <div class="col-sm-10">
                                    <h5><strong>证件号：</strong>
                                        <span id="curridCard"></span>
                                    </h5>
                                </div>
                            </div>

                            <div class="row m-t-lg">
                                <div class="col-sm-10">
                                    <h5><strong>性别：</strong>
                                        <span id="currgender"></span>
                                    </h5>
                                </div>
                            </div>
                            <div class="row m-t-lg">
                                <div class="col-sm-10">
                                    <h5><strong>联系方式：</strong>
                                        <span id="currphoneNumber"></span>
                                    </h5>
                                </div>
                            </div>

                        </div>

                    </div>
                </div>
            </div>

<div class="col-xs-8">
    <!--            列表          -->
    <div class="project-list">
        <table class="table table-hover">
            <tbody id="listBody"></tbody>
        </table>
    </div>
</div>
        </div>
    </div>
    <div class="modal inmodal" id="myModalDe" tabindex="-1" role="dialog" aria-hidden="true">
        <div class="modal-dialog">
            <div class="modal-content animated bounceInRight" style="min-height: 400px;overflow-y: scroll">
                <div class="modal-header">
                    <button type="button" class="close" data-dismiss="modal">
                        <span aria-hidden="true">&times;</span>
                        <span class="sr-only">关闭</span>
                    </button>
                    <i class="fa fa-pencil modal-icon" style="font-size: 60px"></i>
                    <h4 class="modal-title">编辑用户信息</h4>

                </div>
                <div class="formListAdd">


                    <div class="modal-body addList">

                        <div class="form-group col-xs-12">
                            <label>用户照片</label>
                            <input type="file" id="editFile" required="required" multiple="multiple" name="file"
                                   class="form-control"></div>
                    </div>
                    <div class="modal-body addList">

                        <div class="form-group">
                            <div class="col-xs-12">
                                <label>用户名称</label>
                            </div>

                            <div class="col-xs-12">
                                <input type="text" placeholder="输入用户名称" id="userName" name="eqName" class="form-control">
                            </div>

                        </div>


                    </div>
                    <div class="modal-body addList">
                        <div class="form-group">
                            <div class="col-xs-12">
                                <label>用户证件号</label>
                            </div>

                            <div class="col-xs-12">
                                <input type="text" placeholder="输入用户证件号" maxlength="18" id="idCard" name="eqName" class="form-control">
                            </div>

                        </div>
                    </div>

                    <div class="modal-body addList">
                        <div class="form-group">
                            <div class="col-xs-12">
                                <label>用户手机号</label>
                            </div>

                            <div class="col-xs-12">
                                <input type="text" placeholder="输入用户 11位手机号" maxlength="11" id="phoneNumber"  class="form-control">
                            </div>

                        </div>
                    </div>
                    <div class="modal-body addList">

                        <div class="form-group col-xs-12">
                            <label>用户性别</label>
                            <select id="driverGender" class="form-control">
                                <option value="">用户性别</option>
                                <option value="1">男</option>
                                <option value="0">女</option>
                            </select>
                        </div>
                    </div>


                    <div class="modal-footer">
                        <button type="button" class="btn btn-white" id="close" data-dismiss="modal">关闭</button>
                        <button type="button" class="btn btn-success" data-dismiss="modal" id="confirmEditDriver">确定
                        </button>
                    </div>
                </div>
            </div>
        </div>
    </div>
    <div class="modal inmodal" id="myModalRe" tabindex="-1" role="dialog" aria-hidden="true">
        <div class="modal-dialog">
            <div class="modal-content animated bounceInRight" style="min-height: 400px;overflow-y: scroll">
                <div class="modal-header">
                    <button type="button" class="close" data-dismiss="modal">
                        <span aria-hidden="true">&times;</span>
                        <span class="sr-only">关闭</span>
                    </button>
                    <i class="fa fa-pencil modal-icon" style="font-size: 60px"></i>
                    <h4 class="modal-title">重置密码</h4>

                </div>
                <div class="formListAdd">



                    <div class="modal-body addList">

                        <div class="form-group">
                            <div class="col-xs-12">
                                <label>新密码</label>
                            </div>

                            <div class="col-xs-12">
                                <input type="text" placeholder="输入用户名称" id="newpwd" name="eqName" class="form-control">
                            </div>

                        </div>


                    </div>




                    <div class="modal-footer">
                        <button type="button" class="btn btn-white" id="close" data-dismiss="modal">关闭</button>
                        <button type="button" class="btn btn-success" data-dismiss="modal" id="confirmReset">确定
                        </button>
                    </div>
                </div>
            </div>
        </div>
    </div>
    <div class="modal inmodal" id="myModalMessage"  tabindex="-1" role="dialog" aria-hidden="true">
        <div class="modal-dialog" >
            <div class="modal-content animated bounceInRight" style="min-height: 400px;overflow-y: scroll">
                <div class="modal-header">
                    <button type="button" class="close" data-dismiss="modal">
                        <span aria-hidden="true">&times;</span>
                        <span class="sr-only">关闭</span>
                    </button>
                    <i class="fa fa-pencil modal-icon" style="font-size: 60px"></i>
                    <h4 class="modal-title">留言</h4>

                </div>
                <div class="formListAdd">

                    <div class="modal-body addList" style="height: 200px;">
                        <div class="form-group">
                            <div class="col-xs-12">
                                <label>内容</label>
                            </div>

                            <div class="col-xs-12">
                                <textarea type="text" placeholder="输入内容" rows="5" id="message"  class="form-control"></textarea>
                            </div>

                        </div>
                    </div>

                    <div class="modal-footer">

                        <button type="button" class="btn btn-success" data-dismiss="modal" id="confirmSend">发送
                        </button>
                    </div>
                </div>
            </div>
        </div>
    </div>
    <!-- 全局js -->
    <script src="/static/hAdmin/js/jquery.min.js?v=2.1.4"></script>
    <script src="/static/hAdmin/js/bootstrap.min.js?v=3.3.6"></script>

    <!-- 自定义js -->
    <script src="/static/hAdmin/js/content.js?v=1.0.0"></script>

    <script src="/static/hAdmin/js/plugins/sweetalert/sweetalert.min.js"></script>
    <!-- Peity -->
    <script src="/static/hAdmin/js/plugins/peity/jquery.peity.min.js"></script>
    <script src="/static/hAdmin/js/plugins/toastr/toastr.min.js"></script>
    <!-- Peity -->
    <script src="/static/hAdmin/js/demo/peity-demo.js"></script>
    <script src="/static/js/GloJs.js"></script>


<script>
    $(function (){
        let Glo_BaseUrl = $("#gloUrl").attr("gloUValue")
        let Glo_user = localStorage.getItem("userId")
        let id = ""
        let role = "1"

        $.ajax({
            url: Glo_BaseUrl + "/system/user/detail",
            type: "get",
            data: {
                "id":Glo_user
            },
            success: function (data) {
                console.log(data)

                role = data.Data.role
                if (role === "1"){//用户
                    $(".adminFun ").css({display:"none"})
                    $(".docFun ").css({display:"none"})
                    $(".userUnDo ").css({display:"none"})
                    selectInfo()
                    // getOrderList()
                }else if (role === "2"){//管理员
                    $(".docFun ").css({display:"none"})
                    $(".userFun ").css({display:"none"})
                    $(".adminUnDo ").css({display:"none"})
                }
                selectInfo()
            },
            error: function () {
                alert("服务器异常！network error！")
            }
        })
        //个人信息
        function selectInfo(){

            $.ajax({
                url: Glo_BaseUrl + "/system/user/detail",
                type: "get",
                data: {
                    "id":Glo_user,
                    "role":role
                },
                success: function (data) {

                    $("#totalNum").text(data.Data.createTime)
                    $("#curruserName").text(data.Data.userName)
                    $("#userName").val(data.Data.userName)
                    $("#name").text(data.Data.unickName)
                    $("#currphoneNumber").text(data.Data.phoneNumber)
                    $("#phoneNumber").val(data.Data.phoneNumber)
                    $("#curridCard").text(data.Data.idCard)
                    $("#idCard").val(data.Data.idCard)
                    $("#currimg").attr("src",data.Data.img)
                    id = data.Data.iid
                    $("#currgender").html("")
                    if (data.Data.gender === "1") {
                        $("#currgender").append(`<i style="color: #0d8ddb" class="fa fa-user"></i>`)
                    } else {
                        $("#currgender").append( `<i style="color: #e06d80" class="fa fa-user"></i>`)
                    }
                    if (data.Data.role === "1"){
                        $("#role").text("客户")
                    }else if (data.Data.role === "2"){
                        $("#role").text("管理员")
                    }else {
                        $("#role").text("运营管理员")
                    }

                },
                error: function () {
                    alert("服务器异常！network error！")
                }
            })
        }
        //确认编辑
        $("#confirmEditDriver").click(function () {


            var f = $("input[name='editFile']").val();//用户文件内容(文件)
            var formData = new FormData();//这里需要实例化一个FormData来进行文件上传
            if ($("#editFile")[0].files[0] != undefined){
                formData.append("file",$("#editFile")[0].files[0]);
            }

            formData.append("userName",$("#userName").val());
            formData.append("gender",$("#driverGender").val());
            formData.append("idCard",$("#idCard").val());
            formData.append("phoneNumber",$("#phoneNumber").val());

            formData.append("id",id);


            // console.log(f)
            $.ajax({
                url: Glo_BaseUrl + "/system/user/edit",
                type: "post",
                data:formData
                ,
                processData : false,
                contentType : false,
                success: function (data) {

                    if (data.code === 200) {
                        toastr.success("成功", '提示!')
                        $("#close").click()
                    } else {
                        toastr.error(data.msg, '提示!')
                    }
                    selectInfo();

                },
                error: function () {
                    alert("服务器异常！network error！")
                }
            })
        });
        //确认编辑
        $("#confirmReset").click(function () {



            var formData = new FormData();//这里需要实例化一个FormData来进行文件上传


            formData.append("password",$("#newpwd").val());

            formData.append("id",Glo_user);


            // console.log(f)
            $.ajax({
                url: Glo_BaseUrl + "/system/user/updateUserAcc",
                type: "post",
                data:formData
                ,
                processData : false,
                contentType : false,
                success: function (data) {

                    if (data.code === 200) {
                        toastr.success("成功", '提示!')
                        $("#close").click()
                    } else {
                        toastr.error(data.msg, '提示!')
                    }
                    selectInfo();

                },
                error: function () {
                    alert("服务器异常！network error！")
                }
            })
        });
        //获取消息列表
        function getMessageList(){
            let total = 0;//总数
            let pageSize = 6;//每页条数
            let html_dom = $("#listBody")
            $.ajax({
                url: Glo_BaseUrl + "/message/list",
                type: "get",
                data:{
                    "pageSize": 99,
                    "pageNum": 1,
                    "receiveId":Glo_user,
                },
                success: function (data) {
                    let ListStr = ''
                    let specialBtn = ``

                    for (let i = 0; i < data.list.length; i++) {
                        let typeStr = `   <td class="project-completion">
                                                <small>留言方：<span id="dataForClass">${data.list[i].senderName}</span> </small>

                </td>`
                        let item = data.list[i]

                        let statusStr = `<td class="project-status">
                                        <span class="label label-default" >已回复</span>
                                        </td>`
                        specialBtn = `

                                <button class="btn btn-sm btn-danger stopBtn" thisId="${item.id}" title="删除"> <i class="fa fa-close"></i> </button>
                                `
                        if (item.status === '0'){
                            statusStr = `<td class="project-status">
                                        <span class="label label-danger" >未回复</span>
                                        </td>`
                            specialBtn = `
<button class="btn btn-warning btn-sm seeRentDetail" title="查看" id="seeRentDetail" data-toggle="modal" data-target="#myModalMessage"
                 thisId="${data.list[i].id}" senderId="${data.list[i].senderId}"><i class="fa fa-edit"></i>  </button>
                                <button class="btn btn-sm btn-danger stopBtn" thisId="${item.id}" title="删除"> <i class="fa fa-close"></i> </button>
                                `
                        }


                        ListStr +=
                            `<tr>`+statusStr+`
                                        <td class="project-title">
                                            <span > <strong> ${data.list[i].content}</strong> </span>
                                            <br/>
                                              <small>接收方：<span id="EventTime">${data.list[i].receiveName}</span> </small>
                                        </td>


             `+typeStr+`
    <td class="project-completion">
                                                <small>发送时间：<span id="dataForClass">${data.list[i].createTime}</span> </small>

                </td>
                <td class="project-actions">

` + specialBtn + `

                                 </td>
                </tr>
                `

                    }

                    if (data.code !== 500) {
                        html_dom.html("")
                        html_dom.append(ListStr)
                    } else {
                        alert("获取失败")
                    }
                    total = data.total
                    $("#data_total").html(data.total);
                    //停用
                    $(".stopBtn").unbind("click").click(function () {
                        let id = $(this).attr("thisId")
                        swal({
                            title: "您确定要删除此消息？",
                            text: "删除不可恢复！",
                            type: "warning",
                            showCancelButton: true,
                            confirmButtonColor: "#DD6B55",
                            confirmButtonText: "删除",
                            cancelButtonText: "取消",
                            closeOnConfirm: false
                        }, function () {
                            $.ajax({
                                url: Glo_BaseUrl + "/message/del",
                                type: "post",
                                data: {
                                    "id": id,

                                },
                                success: function (data) {
                                    if (data.code === 200) {
                                        swal("停用成功！", "您已经删除了此消息。", "success");
                                        getMessageList()
                                    } else {
                                        swal("停用失败！", "停用失败。", "error");
                                    }

                                },
                                error: function () {
                                    alert("服务器异常！network error！")
                                }
                            })
                        });
                    });
                    $(".seeRentDetail").click(function (){
                        localStorage.setItem("id",$(this).attr("thisId"))
                        localStorage.setItem("senderId",$(this).attr("senderId"))
                    })
                    //发送
                    $("#confirmSend").click(function (){


                        var formData = new FormData();//这里需要实例化一个FormData来进行文件上传

                        formData.append("senderId",Glo_user);
                        formData.append("receiveId",localStorage.getItem("senderId"));

                        formData.append("content",$("#message").val());
                        formData.append("id",localStorage.getItem("id"));



                        // console.log(f)
                        $.ajax({
                            url: Glo_BaseUrl + "/message/add",
                            type: "post",
                            data:formData
                            ,
                            processData : false,
                            contentType : false,
                            success: function (data) {
                                console.log(data)
                                if (data.code === 200) {
                                    toastr.success("成功", '提示!')
                                    $("#close").click()
                                } else {
                                    toastr.error(data.msg, '提示!')
                                }
                                getMessageList();

                            },
                            error: function () {
                                alert("服务器异常！network error！")
                            }
                        })
                    })



                    //停用
                    $(".stopBtn").unbind("click").click(function () {
                        let id = $(this).attr("thisId")
                        swal({
                            title: "您确定要删除此消息？",
                            text: "删除不可恢复！",
                            type: "warning",
                            showCancelButton: true,
                            confirmButtonColor: "#DD6B55",
                            confirmButtonText: "删除",
                            cancelButtonText: "取消",
                            closeOnConfirm: false
                        }, function () {
                            $.ajax({
                                url: Glo_BaseUrl + "/message/del",
                                type: "post",
                                data: {
                                    "id": id,

                                },
                                success: function (data) {
                                    if (data.code === 200) {
                                        swal("停用成功！", "您已经删除了此消息。", "success");
                                        getMessageList()
                                    } else {
                                        swal("停用失败！", "停用失败。", "error");
                                    }

                                },
                                error: function () {
                                    alert("服务器异常！network error！")
                                }
                            })
                        });
                    });
                },
                error: function () {
                    alert("服务器异常！network error！")
                }
            })
        }

        getMessageList()
        $("#confirmAddEq").click(function () {

            var formData = new FormData();//这里需要实例化一个FormData来进行文件上传
            formData.append("senderId",Glo_user);
            formData.append("receiveId",1);
            formData.append("content",$("#content").val());
            formData.append("status","1");
            formData.append("type",role);
            $.ajax({
                url: Glo_BaseUrl + "/message/add",
                type: "post",
                data:formData
                ,
                processData : false,
                contentType : false,
                success: function (data) {

                    if (data.code === 200) {
                        toastr.success("成功", '提示!')
                        $("#close").click()
                    } else {
                        toastr.error(data.msg, '提示!')
                    }
                    getMessageList();

                },
                error: function () {
                    alert("服务器异常！network error！")
                }
            })
        })
        getRoleSetMenu()
        // 退出登录
        $("#logout").click(function (){
            $.ajax({
                url: Glo_BaseUrl + "/admin/logout",
                type: "get",
                data: {

                },
                success: function (data) {
                    location.reload()
                    localStorage.removeItem("dept")
                    localStorage.removeItem("userId")
                },
                error: function () {
                    alert("服务器异常！network error！")
                }
            })
        })
    })

</script>

</body>

</html>
